package com.example.twoeightgang;

import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.Build;
import android.support.v4.app.ActivityCompat;

public class CoinDateOpenHelper extends SQLiteOpenHelper {
    Context context;
    private static int REQUEST_PERMISSION_CODE = 2;
    private static String[] PERMISSION_STORAGE={android.Manifest.permission.READ_EXTERNAL_STORAGE,
            android.Manifest.permission.WRITE_EXTERNAL_STORAGE};

    public CoinDateOpenHelper(Context context, int version) {
        super(context, "coin.db", null, version);
        this.context=context;
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        if(Build.VERSION.SDK_INT>Build.VERSION_CODES.LOLLIPOP){
            if(ActivityCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE)
                    != PackageManager.PERMISSION_GRANTED){
                ActivityCompat.requestPermissions((Activity) context,PERMISSION_STORAGE,REQUEST_PERMISSION_CODE);
            }
        }
        db.execSQL("CREATE TABLE player(id INTEGER PRIMARY KEY,name TEXT,num INTEGER)");
        db.execSQL("CREATE TABLE playname(id INTEGER PRIMARY KEY,name TEXT,num INTEGER)");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
